package com.lala.controller;

import com.lala.util.ResultJson;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 霍明铭
 * @date 2020/3/29 8:44
 */
@Controller
@RequestMapping("/map")
public class MapController {
@GetMapping("/distance")
@ResponseBody
public ResultJson distance(String p1,String p2,String p3,String p4){
    double p11=Double.parseDouble(p1);
    double p22=Double.parseDouble(p2);
    double p33=Double.parseDouble(p3);
    double p44=Double.parseDouble(p4);
    System.out.println(p11);
    System.out.println(p22);
    System.out.println(p33);
    System.out.println(p44);
    GlobalCoordinates source = new GlobalCoordinates(p11, p22);
    GlobalCoordinates target = new GlobalCoordinates(p33, p44);
    double meter2 = getDistanceMeter(source, target, Ellipsoid.WGS84);
    int distance=(new  Double(meter2)).intValue();
     return  new ResultJson(200,"成功",distance);

}
    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid)
    {
        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);
        return geoCurve.getEllipsoidalDistance();
    }

}
